#include "CAblPatrona.h"
#include "CMinionNode.h"

//! Define Ability Data Here
CAblPatrona::CAblPatrona()
{
  // Ability Type
  type = ABL_TARGET;

  // The mp cost of the ability
  cost = 5;

  // Range of the ability ( 0 Indicates non targeted spell )
  range = 100;

  // Radius of the AOE ability ( 0 for non AOE spell )
  radius = 0;

  // Duration of the effect
  duration = 0;

  // Delay of the ability
  delay = 1500;


  // Parameter(s) for ability
  param = new f32;

  // Param[0] = damage ratio
  param[0] = 5.0f;


}

CAblPatrona::~CAblPatrona()
{

  delete param;

}

bool CAblPatrona::effect()
{
  // Step 1 : Range Check
  if ( !caster->IsInRange(target, range) )
  {
    std::cout << "Target is Out of Range. " << std::endl;
    //! TODO: Future message
    //state-> getGUI() -> chatListBox -> addItem(L"Target is Out of Range. ");
    return false;
  }

  // Step 2 : Friendly Fire Check
  if ( caster->getOwner() == target->getOwner() )
  {
    std::cout << "You cannot attack your own units." << std::endl;
    //state-> getGUI() -> chatListBox -> addItem(L"You cannot attack your own units.");
    return false;
  }

  // Step 3 : Mana Check
  if ( caster->getStats().mp < cost )
  {
    std::cout << "You dont have enough mp to cast this spell." << std::endl;
    return false;
  }
  caster->getStats().mp -= cost;

  // Step 4 : Calculates damage
  s32 ratio = (s32) param[0];
  s32 dmg = caster->getStats().mAtk * ratio - target->getStats().mDef;

  if ( dmg < 0 )
    dmg = 1;
  else
    target->updateHp(dmg, true);

  return true;

}
